/* eslint-disable */
export function scaling(w, h, sw, sh) {
  var containerRatio = sw / sh
  var imgRatio = w / h
  var top = 0
  var left = 0
  var s = 1
  if (imgRatio > containerRatio) {
    s = sw / w
    w = sw
    h = sw / imgRatio
    top = sh - h
  } else if (imgRatio < containerRatio) {
    s = sh / h
    h = sh
    w = sh * imgRatio
    left = sw - w
  } else {
    s = sw / w
    w = sw
    h = sh
  }

  return {
    width: w,
    height: h,
    scale: s,
    top,
    left
  }
}
export function getClientWidth() {
  var clientWidth = 0
  if (document.body.clientWidth && document.documentElement.clientWidth) {
    var clientWidth =
      document.body.clientWidth < document.documentElement.clientWidth ?
      document.body.clientWidth :
      document.documentElement.clientWidth
  } else {
    var clientWidth =
      document.body.clientWidth > document.documentElement.clientWidth ?
      document.body.clientWidth :
      document.documentElement.clientWidth
  }
  return clientWidth
}

export function getClientHeight() {
  var clientHeight = 0
  if (document.body.clientHeight && document.documentElement.clientHeight) {
    var clientHeight =
      document.body.clientHeight < document.documentElement.clientHeight ?
      document.body.clientHeight :
      document.documentElement.clientHeight
  } else {
    var clientHeight =
      document.body.clientHeight > document.documentElement.clientHeight ?
      document.body.clientHeight :
      document.documentElement.clientHeight
  }
  return clientHeight
}

export function setFontSize() {
  var html = document.getElementsByTagName('html')[0]
  var oWidth = document.body.clientWidth || document.documentElement.clientWidth
  html.style.fontSize = (oWidth / 1920) * 64 + 'px'
}